#ifndef ANTS_HPP
#define ANTS_HPP

#include <muiltiplant.hpp>
#include <stdexcept>
#include <args.hpp>
#include <vector>
#include <string>
#include <functional>
#include <unordered_map>
#include <unordered_set>

namespace ants {
    class TObject {
        protected:
            int width, height;
            int x, y;
            std::unordered_map<int64_t, std::function<void(void)>> handlers;
            std::unordered_set<TObject *> children;
        public:
            ~TObject();
            void addChild(TObject *);
            void removeChild(TObject *);
            const std::vector<TObject *> &getChildren() const;
            void addHandler(const std::string &, std::function<void(void)>);
            void removeHandler(const std::string &);
            const std::function<void(void)> &getHandler(const std::string&) const;
    };
    class TView : protected TObject{
        protected:
            bool loaded;
        public:
            TView();
            ~TView();
            void onLoad(int64_t key);
            void onUnload(int64_t key);
            bool isLoaded() const;
            void loop() volatile;
            const std::function<void(void)> &getHandler(const std::string &name) const;
    };
    class Console {
        private:
            TView *view;
            args::args *arg;
        public:
            Console(int, const char **);
            ~Console();
            const args::argitem &getArgs(const std::string &title) const;
            const std::vector<args::argitem> &getArgs() const;
            const std::vector<std::string> &getTitles() const;
            size_t getArgCount() const;
            void run();
            void setView(TView *);
    };
    namespace flags{
        extern bool debug;
        extern bool consoled;
        extern int64_t key;
    }
}


#endif
